package com.xy.biz.uc.domain.converter;

import com.xy.biz.uc.domain.bo.ResourceBO;
import com.xy.biz.uc.domain.dto.ResourceDTO;
import com.xy.biz.uc.domain.po.ResourcePO;
import com.xy.biz.uc.domain.query.ResourceQuery;
import com.xy.biz.uc.domain.req.ListResourceRequest;
import com.xy.biz.uc.domain.req.SaveResourceRequest;
import com.xy.tool.util.BeanUtilsEx;

import java.util.Collection;
import java.util.List;

/**
 * 
 * 
 * @author zsp
 * @date 2020-8-19
 */
public class ResourceConverter {
	
	public static ResourcePO toPO(ResourceBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new ResourcePO(), true);
	}
	
	public static List<ResourcePO> toPO(Collection<ResourceBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ResourcePO(), true);
	}
	
	public static ResourceBO fromPO(ResourcePO source) {
		return BeanUtilsEx.copyProperties(source, () -> new ResourceBO());
	}
	
	public static List<ResourceBO> fromPO(Collection<ResourcePO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ResourceBO());
	}
	
	public static ResourceBO toBO(SaveResourceRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new ResourceBO(), true);
	}
	
	public static List<ResourceBO> toBO(Collection<SaveResourceRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ResourceBO(), true);
	}
	
	public static ResourceDTO toDTO(ResourceBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new ResourceDTO());
	}
	
	public static List<ResourceDTO> toDTO(Collection<ResourceBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ResourceDTO());
	}
	
	public static ResourceQuery toQuery(ListResourceRequest source) {
		if(null == source) {
			return null;
		}
		ResourceQuery target = new ResourceQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

}
